package com.xmg.design23.d1_factory.simple;

import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;

/**
 * @Author: mazhongqing
 * @Date: 2021/3/24 15:04
 */
public class FruitFactory {
    public Fruit create(String type){
        switch (type){
            case "苹果":return new Apple();
            case "梨子":return new Pear();
            default: throw new IllegalArgumentException("暂时没有这种水果");
        }
    }


    public static void main(String[] args) {
        FruitFactory factory = new FruitFactory();
        Fruit apple = factory.create("苹果");
        Fruit pear = factory.create("梨子");
        apple.eat();
        pear.eat();
    }
}
